package com.alan.mvvm.base;

import android.annotation.TargetApi;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;

import com.alan.mvvm.utils.Utils;

public class ConstrainBindingLayout<VB extends ViewDataBinding,T> extends ConstraintLayout implements IViewBindingComponents<VB> {

    protected VB mVB;
    protected T t;

    public ConstrainBindingLayout(@NonNull Context context) {
        this(context, null);
    }

    public ConstrainBindingLayout(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        binding();
        initView();
    }

    protected void binding() {
        int res = Utils.getRes(getContext(), this);
        if (res != -1) {
            mVB = DataBindingUtil.inflate(LayoutInflater.from(getContext()), res, this, true);
        }
    }

    protected void initView() {

    }

    public void setData(T data) {
        this.t = data;
    }
}
